package com.niuxiaofa.newlaw.Tools;

import android.graphics.Rect;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;

//import androidx.recyclerview.widget.RecyclerView;

public class SpaceItemDecoration extends RecyclerView.ItemDecoration {

    private int space;

    private  int rows;

    public SpaceItemDecoration(int space,int rows) {
        this.space = space;
        this.rows=rows;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        //不是第一个的格子都设一个左边和底部的间距
        outRect.left = space/2;
        outRect.bottom=space;


        //由于每行都只有2个，所以第一个都是2的倍数，把左边距设为0
        if (parent.getChildLayoutPosition(view) %rows==0) {
            outRect.right = space/2;
            outRect.left = 0;

        }
    }

}